<script>
import { defineComponent, ref, watch, reactive, computed, nextTick, onMounted } from "vue";

import { getAllInvest } from "~/api"
import { useRouter } from 'vue-router'
export default defineComponent({
    setup(props) {
        const formData = reactive({
            pageNum: 0,
            pageSize: 20,
            total: 0,
            status: "",
            orderType: 0
        })
        const statusList = ref(["待支付", "待再预约", "已完成", "未支付"])
        const loading = ref(false)
        const list = ref([])
        const onSubmit = async () => {
            loading.value = true
            try {
                const res = await getAllInvest(formData);
                list.value = res.data.data.InvestList
                formData.total = res.data.data.Total;
            } catch (error) { }
            loading.value = false
        }
        const handleSizeChange = (val) => {
            formData.pageSize = val;
            formData.pageNum = 0;
            onSubmit();
        }
        const handleCurrentChange = (val) => {
            formData.pageNum = val - 1;
            onSubmit();
        }
        const time = computed(() => {
            return ({ CreatedAt, Status, InvestAmount }) => {
                let day = 86400000;
                const endTimestamp = new Date(CreatedAt).getTime() + day * (10 + Status)
                var timestamp = Date.parse(new Date());
                console.log((Math.ceil((endTimestamp - timestamp))))
                return { timestamp: endTimestamp - timestamp, rate: (10 - (Math.ceil((endTimestamp - timestamp) / day))) * InvestAmount / 10 }
            }
        })
        onMounted(() => {
            onSubmit();
        })
        return {
            formData,
            loading,
            list,
            time,
            statusList,
            onSubmit,
            handleSizeChange,
            handleCurrentChange
        }
    }
})
</script>
<template>
    <div>
        <el-form ref="form" :model="formData" label-width="80px" :inline="true">
            <el-form-item label="排序">
                <el-select v-model="formData.orderType" placeholder="请选择" @change="onSubmit">
                    <el-option label="顺序" :value="0"> </el-option>
                    <el-option label="倒序" :value="1"> </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="地址">
                <el-input v-model="formData.address" placeholder="请输入地址" style="width: 360px"></el-input>
            </el-form-item>
            <el-form-item label="状态">
                <el-select v-model="formData.status" placeholder="请选择" @change="onSubmit">
                    <el-option label="全部" value=""> </el-option>
                    <el-option :label="item" :value="index" v-for="(item, index) in statusList" :key="index"> </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">搜索</el-button>
                <!-- <el-button type="warning" @click="exportExcel" :loading="loadingExcel"
          >导出excel</el-button
        > -->
            </el-form-item>
        </el-form>
        <el-table ref="multipleTable" :data="list" v-loading="loading">
            <el-table-column prop="Id" width="60" label="#"> </el-table-column>
            <el-table-column prop="Address" label="发送地址" width="250">
            </el-table-column>
            <el-table-column prop="InvestAmount" label="预约" width="110">
            </el-table-column>
            <el-table-column prop="ReinvestAmount" label="再预约" width="100">
            </el-table-column>
            <el-table-column prop="Status" label="状态" width="100">
                <template #default="scope">
                    <p :style='{ color: [" #e6a23c", "#409eff", "#67c23a", "#f56c6c"][scope.row.Status] }'>
                        {{ statusList[scope.row.Status] }}
                    </p>
                </template>
            </el-table-column>
            <el-table-column prop="CreatedAt" label="创建时间" min-width="160">
            </el-table-column>
        </el-table>
        <el-pagination background layout="total, sizes, prev, pager, next, jumper" :page-size="formData.pageSize"
            :total="formData.total" @size-change="handleSizeChange" @current-change="handleCurrentChange">
        </el-pagination>
    </div>
</template>
<style lang="scss" scoped>
.el-pagination {
    padding: 15px;
    float: right;
}

.total {
    padding: 10px 0;
    font-size: 16px;
}

a {
    color: #1989fa;
}
</style>